package com.qiangesoft.wechat.dto;

import com.qiangesoft.wechat.entity.WxUser;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * 微信用户信息
 *
 * @author qiangesoft
 * @date 2023-09-08
 */
@Data
@ApiModel(value = "微信用户信息")
public class UserDTO implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "openId")
    private String openId;

    @ApiModelProperty(value = "昵称")
    private String nickName;

    @ApiModelProperty(value = "手机号")
    private String phoneNumber;

    /**
     * entity to dto
     *
     * @param entity
     * @return
     */
    public static UserDTO fromEntity(WxUser entity) {
        UserDTO dto = new UserDTO();
        dto.setOpenId(entity.getOpenId());
        dto.setNickName(entity.getNickName());
        dto.setPhoneNumber(entity.getPhoneNumber());
        return dto;
    }

    /**
     * dto to entity
     *
     * @param dto
     * @return
     */
    public static WxUser toEntity(UserDTO dto) {
        WxUser entity = new WxUser();
        entity.setOpenId(dto.getOpenId());
        entity.setNickName(dto.getNickName());
        entity.setPhoneNumber(dto.getPhoneNumber());
        return entity;
    }
}
